package com.ctshk.rpc.order.custom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.common.vo.OrderRefundDTO;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderTouristRefundDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 退款明细 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
public interface CustomizedOrderTouristRefundDetailMapper extends BaseMapper<CustomizedOrderTouristRefundDetail> {

    /**
     * 清空退款明细
     * @param id
     * @param userId
     * @return
     */
    @Update("UPDATE t_customized_order_tourist_refund_detail\n" +
            "SET is_deleted = 1,modified_id = #{user_id}\n" +
            "WHERE refund_id = #{refund_id} AND is_deleted = 0")
    Integer cleanByRefund(@Param("refund_id") Long id, @Param("user_id") Long userId);

    /**
     * 批量更新状态
     * @param id
     * @param type
     * @return
     */
    @Update("UPDATE t_customized_order_tourist_refund_detail\n" +
            "SET refund_status = #{refund_status},modified_id = #{user_id}\n" +
            "WHERE refund_id = #{refund_id} AND is_deleted = 0")
    Integer updateStatusByRefund(@Param("refund_id")Long id, @Param("refund_status") Integer type, @Param("user_id") Long userId);

    /**
     * 退款信息列表
     * @param refundId
     * @return
     */
    @Select("SELECT a.id,a.refund_number,a.refund_account,a.total_receivables,a.paid_in_amount,c.cn_fullname AS touristName,\n" +
            "a.refund_amount,a.refund_account,a.refund_detail,a.refund_reason,a.refund_type,a.remark,a.currency,a.refund_id,a.actual_refund_amount AS approvalAmount\n" +
            "FROM t_customized_order_tourist_refund_detail a\n" +
            "LEFT JOIN t_customized_order_tourist_refund b ON a.refund_id = b.id\n" +
            "LEFT JOIN t_customized_order_tourist_info c ON b.tourist_id = c.id\n" +
            "WHERE a.refund_id = #{refund_id} AND a.is_deleted = 0")
    List<OrderRefundDTO> queryListByRefund(@Param("refund_id")Long refundId);
}
